<?php $field_css_id = to_css_id('field_'.$field->get('field_key')); ?>
<div id="custom_field_<?php echo $field_css_id ?>" class='custom_field'>
    <?php echo form_remote_tag(
                    array('controller'=>'admin/custom_fields',
                          'action'=>'entries_custom_field'),
                    array('update'=>'custom_field_'.$field_css_id)      
                      );
    ?>
    <?php echo hidden_field_tag('entries_custom_fields[id]'); ?>
    <?php echo hidden_field_tag('entries_custom_fields[custom_field_id]', $field->get('id')); ?>
    <?php echo hidden_field_tag('entries_custom_fields['.h($related_key).']',(int)$related_value) ?>
    <h3><?php echo h($field->get('field_key')) ?></h3>
    <p>
<?php
    switch ($field->get('field_type')) { 
        case 'text':
            echo text_field_tag('entries_custom_fields[field_value]',
                               $field->get('default_field_value'),
                               array('size'=>'50',
                                     'id'=>$field_css_id));
            break;       
        case 'textarea':
            echo text_area_tag('entries_custom_fields[field_value]',
                               $field->get('default_field_value'),
                               array('size'=>'50x5',
                                     'id'=>$field_css_id));
            break;
        case 'date':
            $date = strtotime($field->get('default_field_date'));
            if (!$date || $date == '-1') {
                $date = time();
            }
            echo select_datetime(getdate($date), array('prefix'=>'entries_custom_fields[field_date]'));
            break;
    }
?>
</p>
<p><?php echo submit_tag('Save Field') ?>
    <?php echo button_tag('Remove This Field?',
        array('onclick'=>"if(confirm('Are you sure you want to remove this field?')){ $('custom_field_".$field_css_id."').remove();}",
              'class'=>'submit_delete')); ?></p>

<?php echo end_form_tag() ?>
</div>